package cn.tedu.mall.book.service.impl;

import cn.tedu.mall.book.entity.Banner;
import cn.tedu.mall.book.mapper.BannerMapper;
import cn.tedu.mall.book.pojo.dto.BannerAddNewDTO;
import cn.tedu.mall.book.pojo.vo.BannerSimpleVO;
import cn.tedu.mall.book.service.IBannerService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 轮播图业务层实现类
 *
 * @author zxjun
 * @date 2022/6/12 22:14
 */
@Service
public class BannerServiceImpl implements IBannerService {

    @Autowired
    BannerMapper mapper;

    @Override
    public void addNew(BannerAddNewDTO bannerAddNewDTO) {
        Banner banner = new Banner();
        BeanUtils.copyProperties(bannerAddNewDTO,banner);
        banner.setGmtCreate(LocalDateTime.now());
        banner.setGmtModified(LocalDateTime.now());
        mapper.addNew(banner);
    }

    @Override
    public void deleteById(Integer id) {
        mapper.deleteById(id);
    }

    @Override
    public List<BannerSimpleVO> getBanner() {
        return mapper.getBanner();
    }
}
